1679A - AvtoBus - CodeForces Solution


brute force greedy math number theory *900

Please click on ads to support us..

Python Code:

def test():
    n=int(input())
    if(n%2==1 or n<4):
        print(-1)
        return
    n=n//2
    print((n+2)//3,end=" ")
    print(n//2)
    return
T=int(input())
for i in range(T):
    test()

C++ Code:

#include <bits/stdc++.h>

using namespace std;

long long t, n;
int const maxn = 400000;
long long const q = 10e8 + 7;
int a[maxn];

void solve()
{
	cin >> n;
	if (n < 4) cout << -1 << endl;
	else {
		if (n%2!=0) cout << -1 << endl;
		else {
			if (n%6==0) {
				cout << n/6 << " ";
				if (n%4==0) cout << n/4 << endl;
				else cout << (n - 6)/4 + 1 << endl;
			}
			if (n%6==2) {
				cout << (n - 8)/6 + 2 << " ";
				if (n%4==0) cout << n/4 << endl;
				else cout << (n - 6)/4 + 1 << endl;
			}
			if (n%6==4) {
				cout << (n - 4)/6 + 1 << " ";
				if (n%4==0) cout << n/4 << endl;
				else cout << (n - 6)/4 + 1 << endl;
			}
		}
	}
}

int main()
{
	cin >> t;
	while (t--) {
		solve();
	}
}


Comments

Submit
0 Comments
More Questions

1144A - Diverse Strings
1553B - Reverse String
1073A - Diverse Substring
630N - Forecast
312B - Archer
34D - Road Map
630I - Parking Lot
160B - Unlucky Ticket
371B - Fox Dividing Cheese
584B - Kolya and Tanya
137B - Permutation
550C - Divisibility by Eight
5A - Chat Servers Outgoing Traffic
615A - Bulbs
5B - Center Alignment
549A - Face Detection
535B - Tavas and SaDDas
722C - Destroying Array
366A - Dima and Guards
716B - Complete the Word
1461C - Random Events
1627A - Not Shading
141B - Hopscotch
47B - Coins
1466C - Canine poetry
74A - Room Leader
1333D - Challenges in school №41
1475B - New Year's Number
461A - Appleman and Toastman
320B - Ping-Pong (Easy Version)